package com.acwing.partition10;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/3 9:52
 */
public class AC913排队打水 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int[] times = new int[n];
        s = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) times[i] = Integer.parseInt(s[i]);
        writer.write(greedy(times) + "\n");
        writer.flush();
    }

    private static long greedy(int[] times) {
        quickSort(times, 0, times.length - 1);
        long answer = 0;
        for (int i = 0; i < times.length; i++) answer += (long) times[i] * (times.length - i - 1);
        return answer;
    }

    private static void quickSort(int[] nums, int left, int right) {
        if (left >= right) return;
        int i = left - 1, j = right + 1, mid = nums[(left + right) >> 1];
        while (i < j) {
            do i++; while (nums[i] < mid);
            do j--; while (nums[j] > mid);
            if (i < j) {
                int t = nums[i];
                nums[i] = nums[j];
                nums[j] = t;
            }
        }
        quickSort(nums, left, j);
        quickSort(nums, j + 1, right);
    }
}
